package com.biz.hunter.dao;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.biz.hunter.db.entity.Order;
import com.biz.hunter.dbutil.BaseDAO;


@Repository
public class OrderDAO {
	private static final String SQL_GET_ID = "select * from tb_order  where id = ?";
	private static final String SQL_GET_ORDERS="select * from tb_order where hunterId=? order by id desc";
	private static final String SQL_GET_UNORDERS="select * from tb_order where hunterId=? and status=0 order by id desc";
	private static final String SQL_GET_ORDERING="select * from tb_order where hunterId=? and status=1 order by id desc";
	private static final String SQL_GET_ORDERED="select * from tb_order where hunterId=? and (status=3 or status=4 or status=5 ) order by id desc";
	private static final String SQL_GET_ALLORDERS="select * from tb_order where hunterId=? order by id desc";
	private static final String SQL_UPDATE = "update tb_order set status=? where id=?";
	//private static final String SQL_UPDATE_ORDERPRICEDIFF = "update tb_order set priceDiffTime=?,payDiffMoney=? where id=?";
	private static final String SQL_UPDATE_PRICEDIFF = "update tb_order set priceDiffTime=?,payDiffMoney=? where id=?";
	private static final String SQL_GET_OD_COUNT = "SELECT COUNT(*) FROM tb_order WHERE ordescId=?";
	public Order getById(int Id) {
		return  BaseDAO.queryForObject(Order.class, SQL_GET_ID, Id);
	}
	
	public int updOrderPriceDiff(Integer priceDiffTime ,Integer payDiffMoney,long orderId){
		System.out.println(SQL_UPDATE_PRICEDIFF);
		return BaseDAO.execute(SQL_UPDATE_PRICEDIFF, priceDiffTime,payDiffMoney,orderId);
	}
	
	public int updPriceDiff(Integer priceDiffTime ,Integer payDiffMoney,long orderId){
		System.out.println(SQL_UPDATE_PRICEDIFF);
		return BaseDAO.execute(SQL_UPDATE_PRICEDIFF, priceDiffTime,payDiffMoney,orderId);
	}

	public List<Order> getOrdersByHunterId(int hunterId){
		return BaseDAO.queryForList(Order.class, SQL_GET_ORDERS,hunterId);
	}
	
	//待接单
	public List<Order> getUNOrdersByHunterId(int hunterId){
		return BaseDAO.queryForList(Order.class, SQL_GET_UNORDERS,hunterId);
	}
	
	//进行中
	public List<Order> getOrdersingByHunterId(int hunterId){
		return BaseDAO.queryForList(Order.class, SQL_GET_ORDERING,hunterId);
	}
	//已完成(已取消，已拒单，已完成)
	public List<Order> getOrdersedByHunterId(int hunterId){
		return BaseDAO.queryForList(Order.class, SQL_GET_ORDERED,hunterId);
	}
	
	public int updateStatus(int status,int orderid) {
		return BaseDAO.execute(SQL_UPDATE, status,orderid);
	}

	public Long getCountOfOrderDesc(int ordescId) {
		return (Long) BaseDAO.queryOneRowOneCol(SQL_GET_OD_COUNT, ordescId);
	}
	
	/**
	 * 全部订单
	 * @param hunterId
	 * @return
	 */
	public List<Order> getAllOrdersByHunterId(int hunterId){
		return BaseDAO.queryForList(Order.class, SQL_GET_ALLORDERS,hunterId);
	}
	

}
